home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1999
/
MacHack 1999.toast
/
The Hacks
/
Sound-IN-Sane
/
Sound-IN-Sane.c
< prev
next >
Wrap
Text File
|
1999-06-26
|
4KB
|
190 lines
/*=============================*\
Sound-IN-Sane
A MacHack 1999 Production
Developed and Written by
Shawn Platkus
June 25, 1999
\*=============================*/
// This application uses the thus far undocumented MacOS calls that modify the
// Sound Output source which is more commonly known as the Sound Monitor Source.
// This is the same technique that the Sound Source Control Strip uses.
// However, this app takes advantage of a peculiar side effect of these calls to provide
// its bizzare and totally insane functionality.
// System Includes
#include <Dialogs.h>
#include <Devices.h>
#include <Fonts.h>
#include <Menus.h>
#include <NumberFormatting.h>
#include <Quickdraw.h>
#include <Scrap.h>
#include <Sound.h>
#include <ToolUtils.h>
// Local Includes
#include "Sound-IN-Sane.h"
#include "SIS_UI.h"
// Globals
Component device; // Sound Device
ComponentDescription looking; // Sound Device Description
long sndDevRef; // Sound Device Input Reference
Str255 FullNames[kMaxSoundSources + 1]; // Full Descriptions of the Sound Sources
OSType SourceTypes[kMaxSoundSources + 1]; // Selectors for the Sound Sources
//***
// main
//***
void main ( void )
{
ToolboxInit();
MenuBarInit();
EventLoop();
}
//***
// ApplicationInit
//***
Boolean ApplicationInit (void)
{
OSErr err;
Boolean bOKtoRun = true;
NumVersionVariant smVersion;
// Check the sound Manager Version
smVersion.parts = SndSoundManagerVersion();
// Only Sound Manager 3.1 or later implements the SoundComponentGet/SetInfo calls...
// If you know you're going to run on System 7.5 or later, you can skip the SM version check.
if (!(smVersion.whole >= 0x03100000))
{
bOKtoRun = false;
}
else
{
// Get the built-in sound device
looking.componentType = kSoundOutputDeviceType;
looking.componentSubType = 0;
looking.componentManufacturer = kAppleManufacturer;
looking.componentFlags = 0;
looking.componentFlagsMask = 0;
device = FindNextComponent (0, &looking);
// Get the Sound Input Device Reference Number
err = SPBOpenDevice(NULL, siWritePermission, &sndDevRef);
if (err != noErr)
{
bOKtoRun = false;
}
}
if (bOKtoRun)
{
GetSoundSources();
}
return !bOKtoRun;
}
//***
// ApplicationCleanUp
//***
void ApplicationCleanUp (void)
{
SPBCloseDevice(sndDevRef);
return;
}
//***
// GetSoundSources
//***
void GetSoundSources (void)
{
SoundInfoList monitorList;
Handle sourceNames;
OSErr err;
long offset;
short numNames;
int i;
char sourceName[255];
// if (sourceNames != NULL)
{
err = SPBGetDeviceInfo(sndDevRef, siInputSourceNames, &sourceNames);
// siInputSourceNames will return a structure that looks like:
// struct {
// short numNames;
// PString names[numNames];
// };
}
if (err == noErr)
{
// printf ("\nThe sound input source names are:\n");
numNames = (*(short**)sourceNames)[0];
if (numNames > kMaxSoundSources)
{
numNames = kMaxSoundSources;
}
offset = 3;
for (i = 0; i < numNames; i++)
{
BlockMoveData (&((char*)(*sourceNames))[offset],
sourceName, (*(char**)sourceNames)[offset-1]);
sourceName[(*(char**)sourceNames)[offset-1]] = 0;
// CopyCStringToPascal(sourceName, FullNames[i]);
// copy sourceName which is now a CString into the Full Names Array!
// printf (" %s\n", sourceName);
offset += (*(char**)sourceNames)[offset-1] + 1;
}
}
// Get The Sound Source Selectors
SPBCloseDevice(sndDevRef);
return;
}
//***
// CycleSoundSources
//***
void CycleSoundSources ()
{
OSType source;
OSErr err;
// find out which source is monitored
GetSoundOutputInfo(device, siMonitorSource, &source);
if (source == kIntMicSource)
err = SetSoundOutputInfo(device, siMonitorSource, (void *)kCDSource);
else
err = SetSoundOutputInfo(device, siMonitorSource, (void *)kIntMicSource);
}